package com.chrray.position.controller.web;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.chrray.position.domain.FdFeedback;
import com.chrray.position.domain.FdJobCategory;
import com.chrray.position.pojo.dto.BaseIdDto;
import com.chrray.position.pojo.dto.web.FdFeedBackExe;
import com.chrray.position.pojo.dto.web.FdJobCategoryExe;
import com.chrray.position.service.web.WFdFeedbackService;
import com.chrray.position.service.web.WFdJobCategoryService;
import com.chrray.position.util.result.PageBean;
import com.chrray.position.util.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.chrray.position.util.result.ResponseResults.PAGE;
import static com.chrray.position.util.result.ResponseResults.success;

/**
 * 意见反馈表控制器
 *
 * @author lm
 * @since 1.0.1 2024-09-02
 */
@RestController
@RequestMapping("/api/web/jobCategory")
@Api(tags = "职位大类")
@AllArgsConstructor
public class WFdJobCategoryController {
    @Autowired
    private WFdJobCategoryService wFdJobCategoryService;

    @GetMapping("/pageList")
    @ApiOperation("列表")
    public ResponseResult<PageBean<FdJobCategory>> pageCheckList(FdJobCategoryExe dto) {
        return PAGE(wFdJobCategoryService.pageList(dto));
    }


    @GetMapping("/selectById")
    @ApiOperation("查询详情")
    @ApiResponses({
            @ApiResponse(code=200, message = "ok", response = FdJobCategory.class)
    })
    public ResponseResult<FdJobCategory> selectById(BaseIdDto dto){
        return  success(wFdJobCategoryService.getById(dto.getId()));
    }

    @GetMapping("/deletedById")
    @ApiOperation(" 删除")
    public ResponseResult deletedById(BaseIdDto dto){
        return  success(wFdJobCategoryService.removeById(dto.getId()));
    }

    @PostMapping("/updateById")
    @ApiOperation("编辑")
    @ApiResponses({
            @ApiResponse(code=200, message = "ok", response = FdJobCategory.class)
    })
    public ResponseResult updateById(@RequestBody FdJobCategory entity){
        return  success(wFdJobCategoryService.updateById(entity));
    }

    @PostMapping("/save")
    @ApiOperation("添加")
    @ApiResponses({
            @ApiResponse(code=200, message = "ok", response = FdJobCategory.class)
    })
    public ResponseResult save(@RequestBody FdJobCategory entity){
        return  success(wFdJobCategoryService.save(entity));
    }

    @GetMapping("/listAll")
    @ApiOperation("列表-bufenye")
    public ResponseResult<List<FdJobCategory>> listAll(FdJobCategoryExe entity) {
        LambdaQueryWrapper<FdJobCategory> queryWrapper = new LambdaQueryWrapper<>();

        queryWrapper.eq(!ObjectUtils.isEmpty(entity.getName()), FdJobCategory::getName, entity.getName());
        queryWrapper.orderByDesc(FdJobCategory::getCreatedTime);
        return success(wFdJobCategoryService.list(queryWrapper));
    }
}
